﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimeAxis.Admin.Manager
{
    public partial class CreateDoc : System.Web.UI.Page
    {
        public List<Models.Category> categorys = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
                Interfaces.ICategory iCategory = Impls.ImplCategory.GetInstance(db);
                categorys = iCategory.GetList();

                db.Commit();
                db.Dispose();
            }
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            Common.Web.Cookie cookie = new Common.Web.Cookie();
            Models.Doc doc = new Models.Doc();
            doc.Content = this.TextBox1.Text;
            doc.GoodCount = 0;
            doc.Pdate = DateTime.Now;
            doc.Title = this.UserName.Text;
            doc.UsersId = Convert.ToInt32(cookie.GetCookie("LoginUserId"));
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            int docid = Impls.ImplDoc.GetInstance(db).Insert(doc);


            string[] names = Request.Form["querycategory"].Split(new char[] { ',' });
            foreach (string s in names)
            {
                if (!string.IsNullOrEmpty(s))
                {
                    Models.DocCategory dg = new Models.DocCategory();
                    dg.DocId = docid;
                    dg.CategoryId = Convert.ToInt32(s);
                    Impls.ImplDocCategory.GetInstance(db).Insert(dg);
                }
            }


            db.Commit();
            db.Dispose();
            Response.Redirect("../MyList.aspx");
        }
    }
}